package com.powernode.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.powernode.domain.User;
import com.powernode.service.UserService;
import com.powernode.utils.AuthUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 内容:
 * 作者: cy
 */
@RestController
@RequestMapping("p/user")
@Api(tags = "会员管理接口")
public class MemberController {


    @Autowired
    private UserService userService;

    @PutMapping("setUserInfo")
    @ApiOperation("更新会员信息")
    public ResponseEntity<Void> updateUserInfo(@RequestBody User user) {
        String openId = AuthUtil.getOpenId();
        user.setUserId(openId);
        userService.updateMemberInfo(user);
        return ResponseEntity.ok().build();
    }

    ///////////////////////////

    @GetMapping("getUsersByOpenIds")
    @ApiOperation("根据用户的openIds查询用户集合")
    List<User> getUsersByOpenIds(@RequestParam List<String> openIds) {
        return userService.list(new LambdaQueryWrapper<User>()
                .in(User::getUserId, openIds)
        );
    }

}
